package com.hy.main.demo.designmode;

import lombok.AllArgsConstructor;

/**
 *  装饰者模式
 * @Author shy Boy
 * @Date 2022/4/26 - 04 - 26 - 19:58
 * @Description: com.hy.main.demo.designmode
 * @version: 1.0
 */
public interface RotBot {
    void behavior();
}
class RotBotRealize implements RotBot{

    @Override
    public void behavior() {
        System.out.println("扫地");
        System.out.println("洗衣服");
    }
}
@AllArgsConstructor
class RotBotUpgrade implements RotBot {
    private RotBot rotBot;
    // 拓展方法
    public void expandfuncTionality() {
        System.out.println("做饭");
        System.out.println("唱歌");
    }

    @Override
    public void behavior() {
        // 此处调用了继承父类的方法并做了一些拓展
        rotBot.behavior();
        this.expandfuncTionality();
    }
}

class TestRotBot {
    public static void main(String[] args) {
        // 调用有参构造放入RotBot的实现类
        RotBotUpgrade rotUpgrade = new RotBotUpgrade(new RotBotRealize());
        rotUpgrade.behavior();
    }
}
